<style scoped>
.avatar-uploader .avatar {
  width: 50px;
  height: 50px;
  display: block;
  border-radius: 50%;
}
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  border: lightgray 2px solid;
  border-radius: 50%;
  font-size: 28px;
  color: #8c939d;
  width: 50px;
  height: 50px;
  text-align: center;
}
</style>
<template>
   <el-upload
    class="avatar-uploader"
    :auto-upload="false"
    :show-file-list="false"
    @change="getAvatar"
  >
    <img v-if="userInfo.avatar" :src="userInfo.avatar" class="avatar" />
    <el-icon v-else class="avatar-uploader-icon"><User /></el-icon>
  </el-upload>
</template>
<script setup>
import {storeToRefs} from "pinia"
import {useUserInfoStore} from "@/store"
const {userInfo}=storeToRefs(useUserInfoStore())
const {setAvatar}=useUserInfoStore()
const getAvatar=(e)=>{
    console.log(e)
    setAvatar(URL.createObjectURL(e.raw))
}
</script>